<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>8_1_2-keyframes动画</title>
</head>

<body>


    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
    <style>
        /*定义动画名称和每个关键帧的状态*/
        @keyframes animation1 {

            /*起始*/
            0% {
                background-color: red;
                width: 100px;
                height: 100px;
            }

            /*执行到1/4状态*/
            25% {
                background-color: orchid;
                width: 200px;
                height: 200px;
            }

            75% {
                background-color: green;
                width: 150px;
                height: 150px;
            }

            100% {
                background-color: blue;
                width: 200px;
                height: 200px;
            }

        }

        /*若只关注起始与结束状态*/
        @keyframes animation2 {
            from {
                background-color: red;
                width: 100px;
                height: 100px;
            }

            to {
                background-color: blue;
                width: 200px;
                height: 200px;
            }
        }

        .demo {
            width: 100px;
            height: 100px;
            background-color: red;
        }

        .demo-ani {
            animation: animation1 2s linear;
            width: 200px;
            height: 200px;
            background-color: blue;
        }

        /*分别配置animation*/
        .demo-ani2 {
            /*设置关键帧名称*/
            animation-name: animation3;

            /*设置动画时长*/
            animation-duration: 2s;

            /*设置动画播放方式 - 淡入淡出*/
            animation-timing-function: ease-in-out;

            /*设置动画播放方向*/
            animation-direction: alternate;

            /*设置动画播放的次数*/
            animation-iteration-count: infinite;

            /*设置动画的播放状态*/
            animation-play-state: running;

            /*设置播放动画的延迟时间*/
            animation-delay: 1s;

            /*设置动画播放结束应用的元素样式*/
            animation-fill-mode: forwards;
            width: 200px;
            height: 200px;
            background-color: blue;
        }
    </style>

    <div id="Application">
        <div :class="cls" @click="run"></div>
    </div>

    <script>
        const App = Vue.createApp({
            data() {
                return {
                    cls: "demo"
                }
            },
            methods: {
                run() {
                    if (this.cls == "demo") {
                        this.cls = "demo-ani"
                    } else {
                        this.cls = "demo"
                    }
                }
            }
        })
        App.mount("#Application")
    </script>
</body>

</html>